package cn.moningxi.controller;

import cn.moningxi.bean.CustomerLoginLog;
import cn.moningxi.service.CustomerLoginLogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class CustomerLoginLogController {
    @Autowired
    private CustomerLoginLogService customerLoginLogService;

    /**
     * 查询出全部用户的登录日志
     *
     * @param modelAndView
     * @return
     */
    @RequestMapping("/AllCustomerLoginLog/{pageNum}")
    public ModelAndView getAllCustomerLoginLog(ModelAndView modelAndView, @PathVariable("pageNum") Integer pageNum) {
        PageInfo<CustomerLoginLog> logList = new PageInfo<>(customerLoginLogService.queryAll(pageNum), 5);
        modelAndView.addObject("logList", logList);
        modelAndView.setViewName("backstage/member-record-login");
        return modelAndView;
    }

    /**
     * 根据条件（起始时间、用户姓名）查询登录日志
     *
     * @param nameInfo
     * @param beginTime
     * @param endTime
     * @param modelAndView
     * @return
     */
    @RequestMapping("/AllCustomerLoginLog/queryByCon")
    public ModelAndView getCustomerLoginLogByName(String nameInfo, String beginTime, String endTime, ModelAndView modelAndView, Integer pageNum) {
        System.out.println("开始时间：" + beginTime);
        System.out.println("结束时间：" + endTime);
        PageInfo<CustomerLoginLog> logList = new PageInfo<>(customerLoginLogService.queryCustomerLoginLogByName(nameInfo, beginTime, endTime, pageNum), 5);
        //List<CustomerLoginLog> logList = customerLoginLogService.queryCustomerLoginLogByName(nameInfo, beginTime, endTime);
        modelAndView.addObject("inputInfo", nameInfo);
        modelAndView.addObject("logList", logList);
        modelAndView.setViewName("backstage/member-record-login");
        return modelAndView;
    }

}
